package com.winchain.chainbill.bill.biz.send.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import com.winchain.chainbill.bill.biz.send.service.BillArQuotaService;
import com.winchain.chainbill.bill.biz.send.service.BillCrQuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillQuotaSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbSnd>> {
	@Autowired
	private BillArQuotaService billArQuotaService;
	@Autowired
	private BillCrQuotaService billCrQuotaService;

	public void onApplicationEvent(BillEvent<CbSnd> t) {
		CbRec bill = t.getBill().getRec();
		CbSnd send = (CbSnd) t.getBill().getSource();

		String billType = bill.getBillType();
		if ("0".equals(billType)) {
			this.billArQuotaService.block(bill, send);
		} else {
			this.billCrQuotaService.block(bill, send);
		}
	}
}
